<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jquery练习</title>
    <script src="./js/jquery-1.42.min.js"></script>
    <style>
        .selected{
            height: 300px;
            width: 300px;
            background-color: purple;
        }
        /*并集选择器*/
        .select1,.select2{
            height: 100px;
            width: 100px;
            background-color: blue;
        }
        .item-0{
            background-color: green;
            color: white;
        }
        .item-1{
            background-color: darkblue;
            color: white;
        }
        .item-2{
            background-color: cornflowerblue;
            color: white;
        }
    </style>
</head>
<body>
<p></p>
<p></p>
<p></p>
<ul>
    <li>Java</li>
    <li>Python</li>
    <li>PHP</li>
</ul>
<script>
    /*var ps = document.getElementsByTagName("p");
    for (let i = 0; i < ps.length; i++) {
        ps[i].className = "selected";
    }*/
    //jQuery 全局对象---->$
    //jQuery("p").addClass("selected");
    $("p").addClass("selected");
    //给每一个p标签都添加上 select1 select2
    $("p").addClass("select1 select2");//
    //通过回调函数给li添加不同的class值
    $("ul li:last").addClass(function (){
        return "item-" + $(this).index();
    });
</script>
</body>
</html>